package com.springcloud.util.model;

import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPTableEvent;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.dom4j.Element;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: TODO
 * @Create by: 123
 * @Date: 2021/11/22 17:03
 */

@Data
public class TableEventEnhance implements PdfPTableEvent {

    private List<PdfPTableEvent> tableEvents;

    public void addTableEvent(PdfPTableEvent tableEvent) {
        if (tableEvents == null) {
            this.tableEvents = new ArrayList<>();
        }
        tableEvents.add(tableEvent);
    }

    public void addTableEvent(Element tableEvent) {
        if (tableEvents == null) {
            this.tableEvents = new ArrayList<>();
        }
        // todo 构建table event
    }

    @Override
    public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) {
        if (CollectionUtils.isNotEmpty(tableEvents)) {
            for (PdfPTableEvent tableEvent : tableEvents) {
                tableEvent.tableLayout(table, widths, heights, headerRows, rowStart, canvases);
            }
        }
    }
}
